using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FreeLancer.HRB.Domains;
using FreeLancer.HRB.Core;
using FreeLancer.HRB.Core.Web.Controls;

namespace FreeLancer.HRB.WebApp
{
  public partial class PostPrintPreview : WebBasePage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (Request.QueryString["id"] != null && Request.QueryString["id"].Length == 36)
      {
        InitializePageData();
      }
      else
      {
        Response.Redirect(Utils.RelativeWebRoot + "Error404.aspx", true);
      }
    }

    private void InitializePageData()
    {
      Guid id = new Guid(Request.QueryString["id"]);
      Posts postData = GlobalCache.PostServiceInstance.GetByPostId(id);

      h2Title.InnerText = postData.Title;
      spanDateTime.InnerText = postData.DateCreated.ToString();
      divContent.InnerHtml = postData.PostContent;

      Title = postData.Title + " - HRB";

      if (Request.QueryString["print"] != null && Request.QueryString["print"] == "1")
      {
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "DO_PRINT", "window.print();", true);
      }
    }
  }
}
